package com.nuo.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

public class PropertieUtil { 

	/** 
	* ��ݴ������Դ�ļ������classes·����������Դ�ļ���HashMap 
	* return ��Ϊnull
	* */ 
	public static HashMap<String, String> getPropertieMap(String name) { 
		HashMap<String, String> hm = new HashMap<String, String>(); 
		try { 
			InputStream is = hm.getClass().getResourceAsStream(name); 
			Properties pro = new Properties(); 
			pro.load(is); 
			Enumeration<?> e = pro.propertyNames(); 
			while (e.hasMoreElements()) { 
				String key = (String) e.nextElement(); 
				String value = pro.getProperty(key); 
				hm.put(key, value); 
			}
			is.close();
		} catch (IOException e) { 
			e.printStackTrace(); 
		} 
		return hm; 
	}
	
	public static Properties getProperties(String name) { 
		try { 
			InputStream is = PropertieUtil.class.getResourceAsStream(name); 
			Properties pro = new Properties(); 
			pro.load(is); 
			is.close();
			return pro; 
		} catch (IOException e) { 
			e.printStackTrace(); 
			return null;
		} 
	}
	
	/**
	 * test
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println(getProperties("/jdbc-config.properties"));
		
	}
}
